<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网站导航</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f5f5f5;
            color: #333;
            min-height: 100vh;
        }

        .header {
            background-color: #fff;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            padding: 1.5rem 0;
            margin-bottom: 2rem;
            text-align: center;
        }

        .header h1 {
            font-size: 1.8rem;
            color: #2c3e50;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 2rem;
            width: 100%;
        }

        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 300px));
            gap: 2rem;
            padding: 1rem;
            justify-content: center;
        }

        .card {
            background: white;
            border-radius: 10px;
            padding: 1.5rem;
            text-decoration: none;
            color: inherit;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            text-align: center;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 15px rgba(0,0,0,0.2);
        }

        .card h2 {
            font-size: 1.4rem;
            margin-bottom: 0.5rem;
            color: #2c3e50;
        }

        .card p {
            color: #666;
            font-size: 0.9rem;
            line-height: 1.4;
        }
    </style>
</head>
<body>
    <?php
    // 获取当前目录下的所有子目录
    function getSubdirectories($path) {
        $dirs = array();
        if (is_dir($path)) {
            $items = scandir($path);
            foreach ($items as $item) {
                if ($item != '.' && $item != '..' && is_dir($path . '/' . $item)) {
                    // 忽略隐藏目录（以.开头的目录）
                    if (strpos($item, '.') !== 0) {
                        $dirs[] = $item;
                    }
                }
            }
        }
        return $dirs;
    }

    // 获取目录的描述信息（如果存在description.txt文件）
    function getDirectoryDescription($dir) {
        $descFile = $dir . '/description.txt';
        if (file_exists($descFile)) {
            return file_get_contents($descFile);
        }
        return '';
    }

    // 为目录名生成友好的显示名称
    function getFriendlyName($dir) {
        // 将连字符和下划线转换为空格
        $name = str_replace(['-', '_'], ' ', $dir);
        // 将首字母大写
        return ucwords($name);
    }

    // 为不同类型的项目分配图标
    function getDirectoryIcon($dir) {
        $icons = [
            'react' => '⚛️',
            'vue' => '🖖',
            'angular' => '🅰️',
            'node' => '📦',
            'python' => '🐍',
            'java' => '☕',
            'php' => '🐘',
            'docker' => '🐳',
            'kubernetes' => '⎈',
            'default' => '📁'
        ];

        foreach ($icons as $key => $icon) {
            if (stripos($dir, $key) !== false) {
                return $icon;
            }
        }
        return $icons['default'];
    }

    // 获取子目录列表
    $subdirs = getSubdirectories(__DIR__);
    $subsites = array();

    foreach ($subdirs as $dir) {
        $subsites[] = [
            'title' => getFriendlyName($dir),
            'description' => getDirectoryDescription(__DIR__ . '/' . $dir),
            'url' => '/' . $dir,
            'icon' => getDirectoryIcon($dir)
        ];
    }
    ?>

    <header class="header">
        <div class="container">
            <h1>Project Navigation</h1>
        </div>
    </header>

    <main class="container">
        <div class="grid">
            <?php if (empty($subsites)): ?>
            <div class="card">
                <h2>🤔 暂无项目</h2>
                <p>当前目录下没有找到任何子目录</p>
            </div>
            <?php else: ?>
                <?php foreach ($subsites as $site): ?>
                <a href="<?php echo htmlspecialchars($site['url']); ?>" class="card">
                    <h2><?php echo $site['icon']; ?> <?php echo htmlspecialchars($site['title']); ?></h2>
                    <p><?php echo htmlspecialchars($site['description']); ?></p>
                </a>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </main>
</body>
</html>